package com.ren.scale.listener;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ren.scale.constant.MQConstant;
import com.ren.scale.entity.ReclScaleOrder;
import com.ren.scale.service.ReclScaleOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.text.resources.CollationData;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
 * @ClassName: DelayOrderListener
 * @Description: TODO
 * @Author: RZY
 * @DATE: 2022/7/19 16:19
 * @Version: v1.0
 */


@Component
@Slf4j
public class DelayOrderListener {

    @Autowired
    ReclScaleOrderService scaleOrderService;

    @RabbitListener(queues = MQConstant.ORDER_DEAD_QUEUE)
    public void updateDelayOrderStatus(Message message) {
        String orderNo = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("唯一id: {}", orderNo);
        boolean res = scaleOrderService.remove(new LambdaQueryWrapper<ReclScaleOrder>()
                .eq(ReclScaleOrder::getStatus, false)
                .eq(ReclScaleOrder::getOrderNo, orderNo));
        if(res) log.info("定时关单成功");
        else log.info("定时关单失败");
    }
}
